﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace YJKRevitBase.WinForm
{
	public static class WinFormUtilityMethod
	{
		public static Point SetValidFormLocation(System.Windows.Forms.Form inputForm, Point pos)
		{
			Screen[] allScreens = Screen.AllScreens;
			for (int i = 0; i < allScreens.Length; i++)
			{
				System.Drawing.Rectangle workingArea = allScreens[i].WorkingArea;
				if (pos.X < workingArea.Right && pos.X > workingArea.Left && pos.Y > workingArea.Top && pos.Y < workingArea.Bottom)
				{
					return pos;
				}
			}
			System.Drawing.Rectangle workingArea2 = Screen.PrimaryScreen.WorkingArea;
			return new Point((workingArea2.Width - inputForm.Width) / 2, (workingArea2.Height - inputForm.Height) / 2);
		}
	}
}
